<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
  defined('_JEXEC') or die('Retricted Access');
  global $group_name, $group_permission;
  
?>
<script type="text/javascript">
	function checkAll_permission(count)
	{
		var check = false;
		toggle = document.getElementById('toggle');
		if( toggle.checked==true )
		{
			check = true;
		}
		for(var i=0;i<count;i++)
		{
			id='cb'+i;
			cb = document.getElementById(id);
			if (cb) cb.checked = check;
		}	
	}
</script>
<form name="adminForm" action="index.php" method="post">
    <table width="100%">
		<tr>
	
		<td width="80%" valign="top">
			<div style="width:100%;">
				<?php echo $this->menu_User();?>
				<br/>
				<fieldset>
				<legend><?php echo JText::_('Edit Permission'); ?>: <b style="font-size:16px"><?php echo getUsername($this->cid)?></b></legend>
					<table class="adminlist">
						<thead>
							<tr>
								<th width="5%" align="center">
								<?php if ($this->edit) {?>
									<input type="checkbox" name="toggle" id='toggle' value=""  onclick="checkAll_permission(<?php echo count( $this->rows[0]); ?>);" />
								<?php } else { ?>
									<input disabled type="checkbox" name="toggle" id='toggle' value=""  onclick="checkAll_permission(<?php echo count( $this->rows[0]); ?>);" />
								<?php } ?>
								</th>		
								<th width="85%"><?php echo JText::_('Name function') ?></th>
							</tr>
						</thead>
						<tbody>
							<?php
								
							$rows = $this->rows;
							if (JRequest::getVar('usergroup')!='admin')
							{
								if($rows)
								{
									foreach ($group_name as $key=>$group_text)
									{ 
										if (($key=='application' || $key=='payment')&&JRequest::getVar('usergroup')=='guest')
											continue;
							?>
											<tr>
												<td colspan="3">
												
													<b><?php echo $group_text ?></b>
												</td>
											</tr>
							<?php 			
										foreach ($rows[0] as $k=>$per)
										{
											if (in_array($per->name,$group_permission[$key]))
											{ 
												
												?>
													<tr class="<?php echo "row$k"; ?>">		
														<td align="center">
														<?php if ($this->edit) {?>
															<input type="checkbox" id='cb<?php echo $k;?>' name="cb[]" <?php if($rows[1][$k]>0)echo 'checked';?> value="<?php echo $per->value;?>">
														<?php } else { ?>
															<input disabled type="checkbox" id='cb<?php echo $k;?>' name="cb[]" <?php if($rows[1][$k]>0)echo 'checked';?> value="<?php echo $per->value;?>">
														<?php } ?>
														</td>	
														<td>
															<?php echo $per->text;?>
														</td>															
													</tr>
												<?php
											
											}
										}
									}
								}
							}
							else 
							{
								if($rows)
								{
									foreach ($rows[0] as $k=>$per)
									{
						?>
									<tr class="<?php echo "row$k"; ?>">		
										<td align="center">
										<?php if ($this->edit) {?>
											<input type="checkbox" id='cb<?php echo $k;?>' name="cb[]" <?php if($rows[1][$k]>0 || $this->user->usertype=='Super Administrator')echo 'checked';?> value="<?php echo $per->value;?>">
										<?php } else { ?>
											<input disabled type="checkbox" id='cb<?php echo $k;?>' name="cb[]" <?php if($rows[1][$k]>0 || $this->user->usertype=='Super Administrator')echo 'checked';?> value="<?php echo $per->value;?>">
										<?php } ?>
										</td>	
										<td>
											<?php echo $per->text;?>
										</td>															
									</tr>
						<?php 
									}
								}
							} ?>
						</tbody>
					</table>
			    </fieldset>    
			</div>
		</td>
	</tr>
	</table>
	<input type="hidden" name="cid" value="<?php echo $this->cid; ?>" />
	<input type="hidden" name="user_per" value="<?php echo $this->user_per; ?>" />
	<input type="hidden" name="usergroup" value="<?php echo $this->usergroup; ?>" />
	<input type="hidden" name="option" value="<?php echo $this->option; ?>" />
	<input type="hidden" name="view" value="japermission" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>